<?php
#基础函数
include_once('_path.php');
include_once("../includes/init.php");

#获取页面变量
$action = trim($_GET['action']);
$id= trim($_REQUEST['id']) + 0;
	$quote['id'] = string_sql($id);
$uid= trim($_REQUEST['uid']) + 0;
#如果有group_id
if ($id > 0) {
	$sql = "SELECT m.*,mu.name FROM members_message m LEFT JOIN members_info mu ON mu.id = m.uid WHERE m.id=$id";
	$_message = $database->queryFirst($sql);
	if (!$_message['id']) {
		$_REQUEST['referrer'] = "index.php";
		redirect("记录不存在!");
	}
}
#得到post的值
$content = trim($_REQUEST['content']);
$quote['content'] = string_sql($content);
$quote['dateline'] = string_sql(time());
#如果是编辑
if ($action == "add.form") {
	$name = $_message['name'];
	$content = $_message['content'];
        $dateline = $_message['dateline'];
}
#如果是添加操作
if ($action == "add.do") {
		$sql = "INSERT INTO members_message ( content, dateline, rid) VALUES (".$quote['content'].", ".$quote['dateline'].", ".$id.");";
		$database->execute($sql);		
		$_REQUEST['referrer'] = "index.php?uid=".$uid;
		redirect("回复留言成功!");
#如果是编辑操作
} else if ($action == "delete.do" && $id > 0) {
	
	$database->execute("DELETE FROM members_message WHERE id = ".$quote['id'].";");
        $_REQUEST['referrer'] = "index.php?uid=".$uid;
        redirect("删除留言成功!");
}
#样式
$css = array();
$js = array("tiny_mce/tiny_mce");
#菜单
$menu = "members";
include_once("../layout/_header.php");
?>
<div class="main">
<div class="traininc-nav-list">
<ul>
<li><a href="index.php?uid=<?=$uid?>">留言管理</a></li>
<li class="selected"><a href="javascript:">回复留言</a></li>
</ul>
</div>
<script language="javascript" type="text/javascript">
  tinyMCE.init({
    language : "zh-cn",
    theme : "advanced",
    mode: "exact",
    elements : "memo",
    theme_advanced_toolbar_location : "top",
    theme_advanced_buttons1 : "bold,italic,underline,strikethrough,separator,"
    + "justifyleft,justifycenter,justifyright,justifyfull,formatselect,"
    + "bullist,numlist,outdent,indent",
    theme_advanced_buttons2 : "link,unlink,anchor,image,separator,"
    +"undo,redo,cleanup,code,separator,sub,sup,charmap",
    theme_advanced_buttons3 : "",
    height:"300px",
    width:"600px"
});
</script>
<?
if ($action == "add.form") {
?>
<form action="edit.php?action=add.do" method="post" id="form" name="form">
    <input type="hidden" name="uid" value="<?=$uid?>" />
    <input type="hidden" name="id" value="<?=$id?>" />
<div class="box-con">
<table class="table-input">
        <tr>
                <td class="title">用户</td>
                <td><?=$name?></td>
        </tr>
        <tr>
         <td class="title">时间</td>
         <td><?=date(_CONST_DATE_FORMAT.' '._CONST_TIME_FORMAT,$dateline)?></td>
        </tr>
        <tr>
         <td class="title">留言</td>
         <td><?=$content?></td>
        </tr>
         <tr>
         <td class="title">回复</td>
         <td><textarea name="content" id="memo" cols="60" rows="7"></textarea></td>
        </tr>
        <tr>
                <td class="title"> </td>
                <td><input type="submit" name="" value="回复" class="btnA" /><input type="reset" name="" value="取消" class="btnB" /></td>
        </tr>
</table>
</div>
</form>
<?php
}
?>
</div>
<?
include_once("../layout/_footer.php");
?>